<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <base href="<%=request.getContextPath()%>/">
    <link rel="stylesheet" href="static/plugins/layui/css/layui.css">
    <script src="static/plugins/jquery-3.1.0.js"></script>
    <script src="static/plugins/layui/layui.js"></script>
    <script src="static/js/apply.js"></script>
</head>
<body style="background-color: #eee;padding: 15px">
<div class="layui-card">
    <div class="layui-card-body">
        <div id="stepProgressBar" style="margin-bottom: 10px"></div>
        <form class="layui-form" id="dataForm" lay-filter="dataForm">
            <div class="layui-form-item">
                <label for="applyStatus" class="layui-form-label">审核状态</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="applyStatus" id="applyStatus" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="applyUserinfoId" class="layui-form-label">申请人</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="applyUserinfoId" id="applyUserinfoId" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="applyTime" class="layui-form-label">申请时间</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="applyTime" id="applyTime" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="timeRange" class="layui-form-label">用车时间</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="timeRange" id="timeRange" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="applyReason" class="layui-form-label">用车事由</label>
                <div class="layui-input-block">
                    <textarea name="applyReason" id="applyReason" class="layui-textarea" cols="30" rows="6"
                              disabled></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="applyCarId" class="layui-form-label">申请车辆</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="applyCarId" id="applyCarId" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="applyType" class="layui-form-label">是否自驾</label>
                <div class="layui-input-block">
                    <select name="applyType" disabled id="applyType">
                        <option value="1">自驾</option>
                        <option value="2">代驾</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item" id="applyDriverIdDiv">
                <label for="applyDriverId" class="layui-form-label">申请司机</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="applyDriverId" id="applyDriverId" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="examDepartmentUserinfoId" class="layui-form-label">负责人</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="examDepartmentUserinfoId" id="examDepartmentUserinfoId"
                           disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="examDepartmentTime" class="layui-form-label">部门审核时间</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="examDepartmentTime" id="examDepartmentTime" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="examDepartmentContent" class="layui-form-label">部门意见</label>
                <div class="layui-input-block">
                    <textarea name="examDepartmentContent" id="examDepartmentContent" cols="30" rows="6" disabled
                              class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="examAdminUserinfoId" class="layui-form-label">管理员</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="examAdminUserinfoId" id="examAdminUserinfoId"
                           disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="examAdminTime" class="layui-form-label">管理员审核时间</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="examAdminTime" id="examAdminTime" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="examAdminContent" class="layui-form-label">管理员意见</label>
                <div class="layui-input-block">
                    <textarea name="examAdminContent" id="examAdminContent" cols="30" rows="6"
                              class="layui-textarea" disabled></textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="carId" class="layui-form-label">指派车辆</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="carId" id="carId" disabled>
                </div>
            </div>
            <div class="layui-form-item" id="driverIdDiv">
                <label for="driverId" class="layui-form-label">指派司机</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="driverId" id="driverId" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="returnUserinfoId" class="layui-form-label">还车人</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="returnUserinfoId" id="returnUserinfoId" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="returnTime" class="layui-form-label">还车时间</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="returnTime" id="returnTime" disabled>
                </div>
            </div>

        </form>
    </div>
</div>
</body>
<script>
    let form;
    let stepprogress;
    layui.config({
        base: 'static/plugins/stepprogress/'
    }).use(['stepprogress'], function () {
        form = layui.form;
        stepprogress = layui.stepprogress

        getApplyInfo();
    });

    function setStep(applyStatus) {
        let department = '部门审核';
        let admin = '管理员审核';
        let position = 0;
        switch (applyStatus) {
            case 2:
                department = '部门同意';
                position = 1;
                break;
            case 3:
                department = '部门拒绝';
                position = 1;
                break;
            case 4:
                admin = '管理员同意';
                position = 2;
                break;
            case 5:
                admin = '管理员拒绝';
                position = 2;
                break;
            case 6:
                position = 3;
                break;
        }

        return {
            stepItems: [{
                title: '已申请',
            }, {
                title: department,
            }, {
                title: admin,
            }, {
                title: '还车',
            }],
            position
        }
    }

    function getApplyInfo() {
        const dataId = sessionStorage.getItem("dataId");
        $.ajax({
            url: "apply/info/" + dataId,
            method: "get",
            dataType: "json",
            success(res) {
                if (res.code === 200) {
                    if (res.data.applyType === 1) {
                        $("#applyDriverIdDiv").hide();
                        $("#driverIdDiv").hide();
                    } else {
                        $("#applyDriverIdDiv").show();
                        $("#driverIdDiv").show();
                    }
                    let applyStatus = getApplyStatusText(res.data.applyStatus);
                    const formData = {
                        ...res.data,
                        applyUserinfoId: res.data.applyUserinfo.nickname + '-[' + res.data.applyUserinfo.department.name + ']',
                        applyCarId: res.data?.applyCar?.carNo ?? '未指定',
                        applyDriverId: res.data?.applyDriver?.nickname ?? '未指定',
                        timeRange: res.data.applyStartTime + ' - ' + res.data.applyEndTime,
                        examDepartmentUserinfoId: res.data?.examDepartment?.nickname,
                        applyStatus,
                        carId: res.data?.car?.carNo,
                        driverId: res.data?.driver?.nickname,
                        examAdminUserinfoId: res.data?.examAdmin?.nickname,
                        returnUserinfoId: res.data?.returnUserinfo?.nickname
                    }
                    form.val('dataForm', formData);
                    stepprogress.render({
                        elem: '#stepProgressBar',
                        ...setStep(res.data.applyStatus)
                    });
                }
            }
        });
        sessionStorage.removeItem("dataId");
    }
</script>
</html>
